package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.AppointmentMapper;
import com.chaoyi.model.Appointment;
import com.chaoyi.service.AppointmentService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class AppointmentServiceImpl implements AppointmentService {
	@Resource
	private AppointmentMapper appointmentMapper;

	@Override
	public List<Appointment> findList(String offset, String limit) {
		return appointmentMapper.findList(offset,limit);
	}

	@Override
	public int findCount() {
		return appointmentMapper.findCount();
	}

	@Override
	public int saveAppointment(Appointment appointment) {
		return appointmentMapper.saveAppointment(appointment);
	}
	
	@Override
	public String uploadClassifyImg2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.appointmentImgUrlPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.appointmentImgUrlPath, fileName);
	}

	@Override
	public Appointment findAppointmentOne(int id) {
		return appointmentMapper.findAppointmentOne(id);
	}

	@Override
	public int alertAppointmentSave(Appointment appointment) {
		return appointmentMapper.alertAppointmentSave(appointment);
	}

	@Override
	public int deleteAppointment(int id) {
		// TODO Auto-generated method stub
		return appointmentMapper.deleteAppointment(id);
	}
}
